package logger

import (
	"zzxq/common/setting"

	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
	"gopkg.in/natefinch/lumberjack.v2"
)

// Logger Log *zap.SugaredLogger
var getLog *zap.SugaredLogger

//init 初始化日志配置
func Init() {
	w := zapcore.AddSync(&lumberjack.Logger{
		Filename:  setting.Config.APP.LogPath,
		MaxSize:   1024, //MB
		LocalTime: true,
	})

	config := zap.NewProductionEncoderConfig()
	config.EncodeTime = zapcore.ISO8601TimeEncoder
	core := zapcore.NewCore(
		zapcore.NewJSONEncoder(config),
		w,
		zap.NewAtomicLevel(),
	)

	logger := zap.New(core, zap.AddCaller(), zap.AddCallerSkip(1)).Sugar()
	getLog = logger
}

func GetLog() *zap.SugaredLogger {
	return getLog
}
